<?php


function lib_shopattr(&$ctag,&$refObj){
	 global $dsql;
	 //属性处理
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    
    $innertext = $ctag->GetInnerText();
    $row = !empty($row) ? $row : 100;
    $where = " aid=".$refObj->Fields['aid'];
    //先取得属性字段
    $sql = "show full columns from #@__addonshop WHERE Field LIKE 'attr_%'";
    $dsql->Execute('me',$sql);
    $attr = array();
    $attrstr = array();
    while ($rs = $dsql->GetArray('me')){
    	$attr[] = array(
    		'field' => $rs['Field'],
    		'name' => $rs['Comment']
    	);
    	$attrstr[] = $rs['Field'];
    }
    if(empty($attr)){
    	return '';
    }
   //再取得字段的值
   $dsql->Execute('rows', "SELECT ".implode(",",$attrstr)." FROM #@__addonshop WHERE ".$where);
   $rows = $dsql->GetArray('rows');
   if(empty($rows)){
   		return '';
   }
   foreach ($attr as $key=>$att){
   		if(empty($rows[$att['field']])){
   			unset($attr[$key]);
   		}else{
   			$attr[$key]['value'] = explode(",", $rows[$att['field']]);
   		}
   }
   if(empty($attr)){
   		return '';
   }
   $html = '';
   foreach ($attr as $myattr){
	   $html .= '<dl>';
	   $html .= '<dt lab="'.$myattr['field'].'">'.$myattr['name'].'</dt>';
	   $html .= '<dd>';
	   $html .= '<ul>';
	   foreach ($myattr['value'] as $value){
	   		$price = 0;
	   		if($myattr['field'] == 'attr_volume'){
	   			$value = explode("||", $value);
	   			$price = $value[1];
	   			$value = $value[0];
	   		}
	   		$html .= '<li price="'.$price.'"><a href="javascript:;" >'.$value.'</a><i><em>selected</em></i></li>';
	   }
	    $html .= '</ul>';
	    $html .= '<input type="hidden" name="'.$myattr['field'].'" id="'.$myattr['field'].'">';
	   $html .= '</dd>';
	   $html .= '</dl>';
   }
   return $html;
}
?>